package com.wyiot.core.security;

import cn.dev33.satoken.stp.StpUtil;

/**
 * @author yly
 * @since 2022年03月24日
 */

public class UserContext {

        public static String USER_KEY = "USER_TOKEN";

        public UserContext() {}

        public static UserToken currentToken() {
            return (UserToken) StpUtil.getSession().getDataMap().get(USER_KEY);
        }

        public static void setToken(UserToken token) {
            StpUtil.getSession().set(USER_KEY, token);
        }

        public static Long getUserId() {
            Long userId = null;
            if (currentToken() != null) {
                userId = currentToken().getUserId();
            }
            return userId;
        }
    public static String getUserPhone() {
        String userPhone= null;
        if (currentToken() != null) {
            userPhone = currentToken().getUserPhone();
        }
        return userPhone;
    }
    public static String getUserCode() {
        String userCode= null;
        if (currentToken() != null) {
            userCode = currentToken().getUserCode();
        }
        return userCode;
    }

}
